import rclpy
from rclpy.node import Node
from std_msgs.msg import String

class Listener(Node):
    def __init__(self):
        super().__init__("listen_node_py")
        self.get_logger().info("订阅节点已创立")
        self.subscription=self.create_subscription(String,"chatter",self.do_cb,10)
    
    def do_cb(self,msg):
        self.get_logger().info("订阅的数据"+str (msg.data)  )  
def main():
    rclpy.init()
    rclpy.spin(Listener())
if __name__=="__main__":
    main()    